package logic

import (
	"context"
	"renting-demo/model/mysql"

	"renting-demo/goods_srv/goods"
	"renting-demo/goods_srv/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type AddProductLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewAddProductLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AddProductLogic {
	return &AddProductLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// 添加商品
func (l *AddProductLogic) AddProduct(in *goods.AddProductReq) (*goods.AddProductResponse, error) {
	// todo: add your logic here and delete this line
	res := mysql.CreateProduct(mysql.Product{
		GoodsName:   in.GoodsName,
		GoodsPrice:  float64(in.GoodsPrice),
		GoodsStock:  in.GoodsNum,
		GoodsImages: in.GoodsImg,
		Status:      0,
	})
	return &goods.AddProductResponse{
		GoodsID: int64(res.ID),
	}, nil
}
